﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class Publish_SearchResult : System.Web.UI.Page
{
    protected string m_Title = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            GssBL.BLProduct.DOSearch DO = null;
            if (Session["ProductSearch"] != null)
                DO = (GssBL.BLProduct.DOSearch)Session["ProductSearch"];
            //Session.Remove("ProductSearch");

            if (DO == null)
                Response.Redirect(@"Search.aspx", false);
            else
            {
                GssBL.BLProduct BL = new GssBL.BLProduct();
                DataTable dt = BL.QuickSearch(DO);
                if (dt == null || dt.Rows.Count == 0)
                {
                    Response.Redirect(@"SearchNoData.aspx", false);
                }
                else
                {
                    m_Title = "Tìm thấy " + dt.Rows.Count + " sản phẩm";
                    lstProduct.DataSource = dt;
                    lstProduct.DataBind();
                }
            }
        }
    }

    protected string BindProduct(string id, string title, string image, string shortText, object price, object realPrice, object productType)
    {
        string rs = "";
        double p = Convert.ToDouble(price), r = Convert.ToDouble(realPrice);
        int type = Convert.ToInt32(productType);
        // type=1: sales off; type=2: new arrival; type=3 hot product
        if (image != "")
        {
            rs += "<table align='center'><tr><td style='padding: 4px;'><a title='" + shortText + "' href='ProductDetail.aspx?id=" + id + "'>";
            rs += "<img alt='" + shortText + "' src='ProductThumbnail.aspx?id=" + id + "&width=110' border='0' align='left' onerror=\"this.src='../images/noimage90.gif'\" />";
            rs += "</a></td></tr></table>";
        }
        rs += "<p class='title'><a title='" + shortText + "' href='ProductDetail.aspx?id=" + id + "'>" + title + "</a>";
        if (type == 1)
            rs += " <img alt='' border='0' class='icon' src='../images/sale.gif' /></p>";
        else if (type == 2)
            rs += " <img alt='' border='0' class='icon' src='../images/new.gif' /></p>";
        else if (type == 3)
            rs += " <img alt='' border='0' class='icon' src='../images/hot.gif' /></p>";
        else
            rs += "</p>";
        if (p != 0)
        {
            if (r != 0 && r < p)
            {
                rs += "<p class='price'><s>" + p.ToString("##,###") + " VNĐ</s><br><span>" + r.ToString("##,###") + " VNĐ</span></p>";
            }
            else
                rs += "<p class='price'><span>" + p.ToString("##,###") + " VNĐ</span></p>";
        }
        else if (p == 0)
            rs += "<p class='price'>Giá liên hệ</p>";
        return rs;
    }
}
